package com.tinysand.advert.entity;

import com.tinysand.advert.constant.CommonStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

/**
 * 广告投放系统模块推广单元实体类定义
 *
 * Created By TINY
 * Create Time 2020/2/15
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "ad_unit")
@EntityListeners(AuditingEntityListener.class) // 使用JPA审计自动维护日期
public class AdvertUnit {

    /* 推广单元自增主键 */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    /* 推广计划关联主键 */
    @Column(name = "plan_id", nullable = false)
    private Long planId;

    /* 推广单元名称 */
    @Column(name = "unit_name", nullable = false)
    private String unitName;

    /* 推广单元状态 */
    @Column(name = "unit_status", nullable = false)
    private Integer unitStatus;

    /* 广告投放（展示）类型 */
    @Column(name = "position_type", nullable = false)
    private Integer positionType;

    /* 广告预算 */
    @Column(name = "budget", nullable = false)
    private Long budget;

    /* 用户数据创建时间 */
    @Column(name = "create_time", nullable = false)
    @CreatedDate // 使用JPA审计自动维护创建时间
    private Date createTime;

    /* 用户数据更新时间 */
    @Column(name = "update_time", nullable = false)
    @LastModifiedDate // 使用JPA审计自动维护更新时间
    private Date updateTime;

    public AdvertUnit(Long planId, String unitName,
                      Integer positionType, Long budget) {
        this.planId = planId;
        this.unitName = unitName;
        this.positionType = positionType;
        this.budget = budget;
        this.unitStatus = CommonStatus.VALID.getStatus();
    }
}
